<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	 <%
	String token = (String)request.getParameter("token");
	String sid=  (String)request.getParameter("idoc");
	String stToken = (String)request.getParameter("bttoken");
	String sessid = (String)request.getParameter("sessid");
	
	//String[] tt= tokeTemp.split("@");
	String Url = "http://172.17.79.14:8080/test1/viewButton.jsp?token="+stToken+"&idoc="+sid+"&bttoken="+stToken+"&Rando="+System.currentTimeMillis();
	String goUrl ="http://172.17.124.79:8081/sdktest/viewPage.jsp?token=" + token + "&iDocID="+sid+"&ViewType=I&sessid="+sessid;
	String sHomeURL = "http://172.17.79.14:8080/BOE/OpenDocument/opendoc/openDocument.jsp?token=" + token + "&iDocID="+sid+"&ViewType=H";
	%>
  <script type="text/javascript">
   //alert("<%=stToken %>");
   <% 
   
    if(!stToken.equals("null"))
    {
    //request.getSession().setAttribute("bttoken",stToken);
   %>
     //alert('url:<%=Url%>');
      window.location='<%=Url%>';
    <%
    }else
    {
     %>
     //定时刷新获取 bttoken
     setTimeout("getBttoken()",2000);
     //setTimeOut('getBttoken()',5000);
     <%
    }
   
   %>
   var cnt =15;
   function getBttoken()
   {
     
    try{
      var doc,doc1,doc2;
		if(document.all){//IE
		//alert("IE");
		doc = document.frames["ifrChild1"].document;
		doc1 = doc.frames["openDocChildFrame"].document;
		//doc2 = doc1.frames["webiViewFrame"].document;
		}else{//Firefox
		//alert("Firefox");
		doc = document.getElementById("ifrChild1").contentDocument;
		doc1 = doc.frames["openDocChildFrame"].contentDocument;
		//doc2 = doc1.frames["webiViewFrame"].contentDocument;
		}
		//alert("ok");
		var vsrc = doc1.body.innerHTML;;
		var bttoken = getbttokenstr(vsrc);
		//alert("go:<%=goUrl %>&"+bttoken);
		//if(bttoken.indexOf("bttoken")>0)
		//{
		 window.location="<%=goUrl %>&"+bttoken;
		//}else
		//{
		 
		//}
		//alert("gp="+bttoken);
		//alert("goUrl=<%=goUrl %>&bttoken="+bttoken);
		
    }catch(e){
      if(cnt==0)
      {
        //alert("out");
      }
       else{setTimeout("getBttoken()",2000);cnt=cnt-1; }
    }
   }
   
   function getbttokenstr(obj)
   {
    //alert("obj:"+obj);
    var st = obj.indexOf("bttoken=");
    var et = obj.indexOf("&amp;loc=");
    var btoktn = obj.substring(st,et);
    return btoktn;
   }
	/*设置加载过程中的文字状态显示*/
	window.onload = function(){
	
					var i=0;
					LoadText(i);
				
     }
    function LoadText(i){
 		i++;
 		if (i==1){
 			document.getElementById("loadtext").innerHTML="进度：获取报表参数……";
 			setTimeout('LoadText('+i+')',1*1000);
 		}
 		else if(i==2){
 			document.getElementById("loadtext").innerHTML="进度：生成报表样式……";
 			setTimeout('LoadText('+i+')',1*1000);
 		}
 		else if(i==3){
 			document.getElementById("loadtext").innerHTML="进度：生成报表脚本……";
 			setTimeout('LoadText('+i+')',1*1000);
 		}
 		else if(i==4){
 			document.getElementById("loadtext").innerHTML="进度：预加载报表……";
 			setTimeout('LoadText('+i+')',1*1000);
 		}
 }
  </script>
  </head>
 
  <body>
  <%if(stToken==null||stToken.equals("null")){ %>
   <iframe id="ifrChild1" name="ifrChild1" src="<%=sHomeURL %>" height="100" width="100"></iframe>
   <%} %>
   <div style="width;1000px;height:400px;display:block;">
   <table width=1000px height=350px align="center" >
	<tr>
		<td valign="bottom"><span id="loadtext" name="loadtext" style="font-family:'微软雅黑';font-size:13px;color:#0f3e94; ">连接服务器中……</span></td>
	</tr>
</table>
   </div>
  </body>
</html>
